<!-- 我的话题 -->
<template>
	<z-paging ref="pagings" v-model="dataList" @query="queryList" v-if="isshow"
	:default-page-no="1" :default-page-size="10"
	:hide-empty-view="Boolean(dataList.length)" class="gray">
		<view slot="top">
			<u-tabs :list="tabList" @click="changeTab" :scrollable="false" :current="currentIndex"
			lineHeight="10" lineWidth="40"></u-tabs>
		</view>
		<topItem :dataList="dataList" :type="type" @goDetail="goDetail" :isMyFb="true" v-if="current == '我发布的'"
			@continueRelease="continueRelease" @delRelease="delRelease" />
		<danger-popup :show="delShow" title="提示" content="话题删除后不可恢复,确认吗？" @confirm="sureDel" @cancel="delShow =false">
		</danger-popup>
	</z-paging>
</template>

<script>
	import topItem from '../../modules/topic_item.vue';
	import dangerPopup from '@/components/dangerPopup/dangerPopup.vue';
	import {
		memberTopic,
		delTopic
	} from '@/apis/apis.js';
	export default {
		components: {
			topItem,
			dangerPopup
		},
		data() {
			return {
				isshow:false,
				dataList: [],
				tabList: [{
						name: '我发布的',
						type: 1
					},
					{
						name: '我参与的',
						type: 2
					}
				],
				current: '我发布的',
				type: 1, // （1：我发布的，2：我查看的)
				delShow: false,
				isshow:false,
				delId: "",
				currentIndex:0
			};
		},
		onShow() {
			this.isshow = true
			if(this.type == 1){
				this.currentIndex = 0
			}else{
				this.currentIndex = 1
			}
		},
		onHide() {
			this.isshow = false
		},
		methods: {
			queryList(pageNo = 1, pageSize = 1) {
				memberTopic({
					pageNum: pageNo,
					pageSize: pageSize,
					getType: this.type
				}).then(res => {
					console.log(res);
					res.data.forEach(el => {
						if (el.workKey) {
							el.words = el.workKey.split(',');
						}
					});
					this.$refs.pagings.complete(res.data);
				});
			},
			goDetail(item) {
				console.log(item);
				// examine 0：待审核，1：审核通过，2：驳回
				// status -1 待发布 0 启用  1 禁用
				if (item.status > -1) {
					uni.navigateTo({
						url: '/pages/topic/topicDetail/topicDetail?id=' + item.id
					});
				}
			},
			// 继续编辑
			continueRelease(e) {
				uni.navigateTo({
					url: '/pages/topic/release/release?id=' + e
				});
			},
			delRelease(e) {
				this.delId = e
				this.delShow = true
			},
			async sureDel() {
				const res = await delTopic(this.delId);
				if (res.code == 200) {
					this.delShow = false
					uni.showToast({
						title: '话题已删除',
						icon: 'none'
					});
					// this.$refs.pagings.reload();
				}
			},
			changeTab(e) {
				this.type = e.type;
				this.queryList();
			}
		},
		onReachBottom() {
			console.log(123);
		}
	};
</script>

<style lang="scss" scoped>
	.gray {
		background-color: #f8f8f8;
	}
</style>
